﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Engine.Components.Workers
{
    public class FileOperation : Abstract.WorkerBase
    {
        #region PRIVATE
        DataSchema.CollectionSchema _cs;
        #endregion


        #region FACTORY
        private FileOperation(HunterPluginSDK.Interface.IProgressHandler ph, DataSchema.CollectionSchema cs)
        {
            this.ProgressHandler = ph;
            _cs = cs;
        }
        static public Engine.Components.Interface.IWorker CreateWorker(HunterPluginSDK.Interface.IProgressHandler ph, DataSchema.CollectionSchema cs)
        {
            return new FileOperation(ph, cs);
        }
        #endregion

        protected override void DoMyJob(object o)
        {
            try
            {
                FileMatcherInfo fie = o as FileMatcherInfo;
                if (fie != null)
                {
                    string topath = _cs.GetItemPath(fie.Item);
                    Engine.IO.FileTools.CopyItem(fie.FileInfo.FileInfo, topath, this.ProgressHandler);
                }
            }
            catch (Exception ex)
            {
                ProgressHandler.WriteToOutput(ex.ToString(), HunterPluginSDK.LogPriority.ERROR);
            }
        }
    }
}
